package controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import constants.Constants.Colors;

import modelo.Features;
import modelo.Features.Cabeza;
import modelo.Features.Cuerpo;
import modelo.Features.Orden;
import modelo.Features.Titulo;
import modelo.Features.VelloFacial;
import modelo.Game;
import modelo.Player;
import modelo.Suspect;
/**
 * this class will handle all of the message to be handle from the server 
 * @author Jose Luis Garcia && Alvaro Blazquez Checa
 *
 */
public class ServerMessage implements Serializable, Protocol{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ServerCommands command;
	private List<String> infoList;
	
	/**
	 * this construct will create the command to execute
	 * @param command
	 */
	public ServerMessage(ServerCommands command){
		this.command = command;
		fillMessage();
	}
	/**
	 * this will return the command to execute
	 * @return
	 */
	public ServerCommands getCommand(){
		return command;
	}
	/**
	 * this will return the list of param to be handle 
	 * @return
	 */
	public List<String> getInfoList(){
		return infoList;
	}
	/**
	 * this will set the list of param to be handle
	 * @param infoList
	 */
	public void setInfolist(List<String> infoList){
		this.infoList = infoList;
	}
	/**
	 * this will fill the message to be send to the client with the necesary params
	 */
	@Override
	public void fillMessage() {
		infoList = new ArrayList<String>();
		switch(command){
		case GIVE_ME_PLAYER_INFO: 
		{
			for(Colors c : Colors.values()) infoList.add(c.toString());
		}
		break;
		case YOUR_TURN:
		{
			infoList.add(Game.getInstance().getCurrentPlayer().getPlayerName()); //playerName
			infoList.add(Game.getInstance().getCurrentMisa()); //misa
			infoList.add(String.valueOf(Game.getInstance().getTurn())); //turn
			infoList.add(String.valueOf(Game.getInstance().getCurrentPlayer().getUbication().getSquareNum())); //String ubication 
			infoList.add(Game.getInstance().getCurrentPlayer().getUbication().getSquareName()); //String ubicationName
			infoList.addAll(Game.getInstance().getBoard().getReachableSquares(Game.getInstance().getCurrentPlayer().getUbication())); //List<String> reachableSquares 
		}
		break;
		case TURN_INFO:
		{
			infoList.add(Game.getInstance().getCurrentPlayer().getPlayerName()); //playerName
			infoList.add(Game.getInstance().getCurrentMisa()); //misa
			infoList.add(String.valueOf(Game.getInstance().getTurn())); //turn
			infoList.add(String.valueOf(Game.getInstance().getCurrentPlayer().getUbication().getSquareNum())); //String ubication 
			infoList.add(Game.getInstance().getCurrentPlayer().getUbication().getSquareName()); //String ubicationName
			infoList.addAll(Game.getInstance().getBoard().getReachableSquares(Game.getInstance().getCurrentPlayer().getUbication()));
		}
		break;
		case END : 
		{
			infoList.add(Game.getInstance().getScore().toString());
		}
		break;
		
		case TAKE_MONK_CARDS: 
		{
//			for(int i=0;i<24;i++) infoList.add(i, "0");
//			for(Monje m:Game.getInstance().getCurrentPlayer().getMonkCards()) {
//				infoList.add(m.getId(), "1");
//			}
		}
		break;
		
		case REJECTED:
		{
			String info = "Partida en curso\n";
			info+= Game.getInstance().getPlayerList().size() + " " + "jugadores actualmente\n";
			for(Player p : Game.getInstance().getPlayerList()){
				info+=p.getPlayerName() + "\n";
			}
			info+="Intentelo mas tarde";
			infoList.add(info);
		}//SUSPECTS
		
		case QUESTIONS:
		{
			List<String> valuesSet1 = new ArrayList<String>();
			Cabeza[] cabezaValues= Features.Cabeza.values();
			valuesSet1.add("Cabeza");
			for(int i=0;i<cabezaValues.length;i++) {
				valuesSet1.add(cabezaValues[i].toString());
			}
			valuesSet1.add("|");
			
			List<String> valuesSet2 = new ArrayList<String>();
			Cuerpo[] cuerpoValues= Features.Cuerpo.values();
			valuesSet2.add("Cuerpo");
			for(int i=0;i<cuerpoValues.length;i++) {
				valuesSet2.add(cuerpoValues[i].toString());
			}
			valuesSet2.add("|");
			
			List<String> valuesSet3 = new ArrayList<String>();
			Orden[] ordenValues= Features.Orden.values();
			valuesSet3.add("Orden");
			for(int i=0;i<ordenValues.length;i++) {
				valuesSet3.add(ordenValues[i].toString());
			}
			valuesSet3.add("|");
			
			List<String> valuesSet4 = new ArrayList<String>();
			Titulo[] tituloValues= Features.Titulo.values();
			valuesSet4.add("Titulo");
			for(int i=0;i<tituloValues.length;i++) {
				valuesSet4.add(tituloValues[i].toString());
			}
			valuesSet4.add("|");
			
			List<String> valuesSet5 = new ArrayList<String>();
			VelloFacial[] velloFacialValues= Features.VelloFacial.values();
			valuesSet5.add("VelloFacial");
			for(int i=0;i<velloFacialValues.length;i++) {
				valuesSet5.add(velloFacialValues[i].toString());
			}
			valuesSet5.add("|");
			
			List<String> monkNames = new ArrayList<String>();
			monkNames.add("?");
			for(Suspect monk: Game.getInstance().getPlayerList().get(0).getHojaSospechosos()) {
				monkNames.add(monk.getMonje().getName());
			}
			
			
			List<String> playerNames = new ArrayList<String>();
			playerNames.add("?");
			for(Player player: Game.getInstance().getPlayerList()) {
				playerNames.add(player.getPlayerName());
			}
			
			
			infoList.addAll(valuesSet4);
			infoList.addAll(valuesSet3);
			infoList.addAll(valuesSet1);
			infoList.addAll(valuesSet2);
			infoList.addAll(valuesSet5);
			infoList.addAll(monkNames);
			infoList.addAll(playerNames);
			
			
		}
		break;
		
		case SUSPECTS:
		{				
		}
		break;
		
		default:
			break;	
		}
	}
			
}	